package home.contaduria.support.util;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

import org.joda.time.format.DateTimeFormat;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.ui.Model;
import org.springframework.web.util.UriUtils;
import org.springframework.web.util.WebUtils;

public class WebUtil {

	public static String encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest){
		String enc = httpServletRequest.getCharacterEncoding();
        if (enc == null) {
            enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
        }
        try {
            pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
        }
        catch (UnsupportedEncodingException uee) {}
        return pathSegment;
	}
	
	public static void addDateTimeFormatPatterns(Model uiModel, String attributeName){
		uiModel.addAttribute(attributeName, DateTimeFormat.patternForStyle("S-", LocaleContextHolder.getLocale()));
	}
	
}
